package testcase.app;

import java.io.File;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import api.app.ApiUserModify;
import common.Host;
import common.ImageOperation;
import common.TestData;

/**
 * 帮忙医APP修改个人资料ApiUserModify接口测试用例
 * @author lipeng
 *
 */
public class TestApiUserModify
{
	 /**
	  * 帮忙医APP修改个人资料ApiUserModify接口测试环境数据驱动
	  * @return 测试数据
	  * @throws Exception
	  */
    @DataProvider(name = "Test")
    public static String[][] testApiUserModifyDataProvider() throws Exception{
    	Host.setup("Test");
    	TestData td = new TestData("app/TestApiUserModify.xml");
    	return td.getParam();
    }
    
    /**
     * 帮忙医APP修改个人资料ApiUserModify接口测试用例
     * @param caseName  -用例名称
     * @param photo     -头像
     * @param filename  -文件名
     * @param sex       -性别
     * @param name      -姓名
     * @param addition1 -昵称
     * @param userAccount-电话号码
     * @param idcard     -身份证号码
     * @throws Exception
     */
    @Test (dataProvider= "Test",groups={"Test"})
    public void testApiUserModifyTestCase(String caseName,String photo,String filename,String sex,String name,String addition1,String idcard,String userAccount)throws Exception{
    	String result = null;
    	if(!photo.isEmpty()){
   			    //获取图片base64编码字符串
    			String photoPath =System.getProperty("user.dir")
    					+ File.separator + "resources"
    					+ File.separator + "image"
    					+ File.separator + photo;
    			String base64photo = ImageOperation.base64Encode(photoPath);
    		
    		//调用接口并将接口返回数据转换成json格式	
    		result = ApiUserModify.post(base64photo, filename, sex, name,addition1 , idcard , userAccount);
    	}
    	else {
			result = ApiUserModify.post(null, null, null, null, null, null, null);
		}
    	JSONObject jsonResult;
    	if(result==null || result.isEmpty()){
    		jsonResult=null;
    	}
    	else{
    		jsonResult = new JSONObject(result);
    	}
    	
    	//设置检查点
    	switch (caseName)
		{
            case "Success":
				Assert.assertEquals(jsonResult.getString("Message"),"修改成功");
				Assert.assertFalse(jsonResult.getString("photopath").isEmpty());
				break;
			default:
				Assert.fail();
				break;
		}
    }
}
